package com.l2jserver.gameserver.util.audit;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.l2jserver.Config;
import com.l2jserver.util.lib.Log;

/**
 * @author fissban
 */
public class EnchantSkillAudit
{
	private static final Logger _log = Logger.getLogger(Log.class.getName());
	
	static
	{
		new File("log/EnchantSkillAudit").mkdirs();
	}
	
	/**
	 * Logs a Enchant Skill users action into a file.
	 * @param UserName the char name
	 * @param params - skill, book, support, chance
	 */
	public static void auditSkillEnchantAction(String UserName, String params)
	{
		final SimpleDateFormat _formatter = new SimpleDateFormat("dd/MM/yyyy H:mm:ss");
		final String date = _formatter.format(new Date());
		String name = com.l2jserver.util.Util.replaceIllegalCharacters(UserName);
		if (!com.l2jserver.util.Util.isValidFileName(name))
		{
			name = "INVALID_USER_NAME_" + date;
		}
		
		final File file = new File("log/EnchantSkillAudit/" + name + ".txt");
		try (FileWriter save = new FileWriter(file, true))
		{
			save.write(date + ">" + params + Config.EOL);
		}
		catch (IOException e)
		{
			_log.log(Level.SEVERE, "EnchantSkillAudit for Users " + UserName + " could not be saved: ", e);
		}
	}
}